﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace CloudWars
{
    public class FloatingText
    {
        public Point Location { get; set; }
        public SpriteFont Font { get; set; }

        public Color Color { get; set; }
        public string Text { get; set; }

        private bool showText;

        private int offset;
        private int maxOffset = 30;

        public FloatingText(SpriteFont font)
        {
            Font = font;
        }

        public FloatingText(SpriteFont font, int floatRange)
        {
            Font = font;
            maxOffset = floatRange;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            if (showText)
            {
                spriteBatch.DrawString(Font, Text, new Vector2(Location.X + 12, Location.Y + 10 - offset), Color);
            }
        }

        public void Update()
        {
            if (showText)
            {
                offset++;

                if (offset > maxOffset)
                {
                    offset = 0;
                    showText = false;
                }
            }
        }

        public void ShowText(Point location, string text, Color color)
        {
            Text = text;
            Color = color;
            Location = location;
            showText = true;
        }
    }
}
